<template>
	<view >
		<video v-if='content && content.video  && isReview == false' id="video" :src="content.video" controls autoplay="false" object-fit="fill"
			style='width:100%;height: 90vh;'></video>
		<view v-if='content && content.content' class="content"> 
			<u-parse :content="content.content"></u-parse>
			<view style='height:100px'>
				
			</view>
		</view>
		<view v-if='content.extraData && content.extraData.productId > 0 && isReview == false' class='footer'>
			<view >
				<u-row>
					<u-col span='6'>
						<view style='padding:10px'>
							<u-button type='success' shape='circle' text='分享海报' @click='toShare(content.id)'></u-button>
						</view>
					</u-col>
					<u-col span='6'>
						<view style='padding:10px'>
							<u-button type='primary' shape='circle' text='我要参加' @click='toDetail(content.extraData.productId)'></u-button>
						</view>
					</u-col>
				</u-row>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				content: '',
				isReview: true
			}
		},
		onShareAppMessage(res) {
			let userId = uni.getStorageSync('userId')
			if (userId == '') {
				userId = 1
			}
			return {
				title: '甘链农投',
				desc: this.content.title,
				path: `/pages/content/detail?id=${this.content.id}&recommendedUser=${userId}`,
				imageUrl: this.content.cover
			}
		},
		onShareTimeline() {
			let userId = uni.getStorageSync('userId')
			if (userId == '') {
				userId = 1
			}
			return {
				title: '甘链农投',
				desc: this.content.title,
				path: `/pages/content/detail?id=${this.content.id}&recommendedUser=${userId}`,
				imageUrl: this.content.cover
			}
		},
		onShow(){
		},
		onLoad(options) {
			if(typeof(options.id) != 'undefined'){
				let token = uni.getStorageSync('api_token')
				if(token == ''){
					let _this = this
					uni.login({
						success(result) {
							let data = {
								code: result.code,
							}
							if(typeof(options.recommendedUser) != 'undefined'){
								data.recommendedUser = options.recommendedUser
							}else{
								data.recommendedUser = 2
							}
							_this.request.get(`wechat/mini/login`, data).then((res) => {
								uni.setStorageSync('api_token', res.data.token)
								_this.request.get(`api/user`).then((res) => {
									uni.setStorageSync('userId',res.data.id)
									_this.getContent(options.id)
								})
							})
						}
					})
				}else{
					this.getContent(options.id)
				}
			}else if(typeof(options.scene) != 'undefined'){
				let optionData = options.scene.split('-')
				console.log(optionData)
				let token = uni.getStorageSync('api_token')
				if(token == ''){
					let _this = this
					uni.login({
						success(result) {
							let data = {
								code: result.code,
							}
							if(typeof(optionData[1]) != 'undefined'){
								data.recommendedUser = optionData[1]
							}else{
								data.recommendedUser = 2
							}
							_this.request.get(`wechat/mini/login`, data).then((res) => {
								uni.setStorageSync('api_token', res.data.token)
								_this.request.get(`api/user`).then((res) => {
									uni.setStorageSync('userId',res.data.id)
									_this.getContent(optionData[0])
								})
							})
						}
					})
				}else{
					this.getContent(optionData[0])
				}
			}else{
				uni.showModal({
					title: '',
					content: '参数错误',
					showCancel: false,
					success() {
						uni.switchTab({
							url: '/pages/index/index'
						})
					}
				})
			}
		},
		methods: {
			getContent(id){
				this.request.get(`api/options/IS_REVIEW`).then((res) => {
					console.log(res.data)
					this.isReview = res.data.value
				})
				this.request.get(`api/contents/${id}`).then((res) => {
					console.log(res.data)
					this.content = res.data
					uni.setNavigationBarTitle({
						title: res.data.title
					})
				})
			},
			toDetail(id){
				uni.navigateTo({
					url: `/pages/cart/cooperation?id=${id}`
				})
			},
			toShare(id){
				uni.navigateTo({
					url: `/pages/content/poster?id=${id}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.content{
		// padding: 10px;
	}
</style>